package com.greate.community.service.master;

import com.greate.community.dao.admin.SectionForbidMapper;
import com.greate.community.entity.admin_master.Section;
import com.greate.community.util.CommunityUtil;
import com.greate.community.util.RedisKeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SectionForbidService {

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    SectionForbidMapper sectionForbidMapper;

    /**
     * 全区禁言
     * @return
     */
    public String allSectionForbid() {
        redisTemplate.opsForValue().set(RedisKeyUtil.getForbidAllSectionForbid(),"全区禁言");
        return CommunityUtil.getJSONString(200,"禁言成功");
    }

    /**
     * 全区解禁
     * @return
     */
    public String cancelSectionForbid() {
        redisTemplate.delete(RedisKeyUtil.getForbidAllSectionForbid());
        return CommunityUtil.getJSONString(200,"已取消全分区禁言");
    }

    /**
     * 按分区禁言
     * @param sections
     * @return
     */
    public String someSectionForbid(List<Integer> sections) {
        //
        redisTemplate.opsForSet().add(RedisKeyUtil.getForbidSomeSectionForbid(),sections);
        return CommunityUtil.getJSONString(200,"禁言成功");
    }

    /**
     * 按分区解禁
     * @param sections
     * @return
     */
    public String cancelSomeSectionForbid(List<Integer> sections) {
        redisTemplate.opsForSet().remove(RedisKeyUtil.getForbidSomeSectionForbid(),sections);
        return CommunityUtil.getJSONString(200,"已取消选中分区禁言");
    }

    /**
     *评论属于那个分区
     * @return
     */
    public int discussOfSection(int discussPostId){
       return sectionForbidMapper.discussOfSection(discussPostId);
    }

    /**
     * 所有分区信息
     * @return
     */
    public List<Section> getAllSection() {
       return sectionForbidMapper.getAllSection();
    }
}
